<template>
	<view class="">
		<button type="default" @click="star">重置</button>
		<button type="default" @click="play">开始</button>
	<br>
		<view class="ul">
			<li v-for="(item,index) in list" @click="btn(item)" :class="ab==item?'active':''">{{item}}</li>
		</view>
	<text>用时：{{tis}} 秒</text>
	</view>
</template>

<script>
	export default{
		data() {
			return {
				list:"",
				times:1,
				ab:0,
				bg:false,
				time:"",
				tis:0,
				ltt:false
			}
		},
		created() {
		   this.star()
		},
		
		methods:{
			jd(index){
			
				if(index==0){
					this.ltt=false
					
				}else{
					this.ltt=true
				}
			}
			
			
			,
			play(){
				var self=this
				uni.showActionSheet({
				    itemList: ['简单', '困难'],
				    success: function (res) {
				        // console.log('选中了第' + (res.tapIndex + 1) + '个按钮');
						if(res.tapIndex + 1==1){
							self.ltt=false
							}else{
								self.ltt=true
							}
						// }if(res.tapIndex + 2){
						// 	self.ltt=true
						// }
						console.log(self.ltt)
						self.bg=true
							
										self.time= setInterval(()=>{
											this.tis++
						// console.log(this.tis)
										},1000)
						
				    },
				    fail: function (res) {
				        console.log(res.errMsg);
				    }
				});
				
			},
			star() {
				clearInterval(this.time)
				this.ab=0
				this.tis=0
				this.times=1
				this.bg=false
				this.ltt=false
				var arrlength = 5 * 5;
				var arr = new Array(arrlength);
				var index = 0;
				for(var i = 1; i <= arrlength; i++) {
				    //生成随机数
				    var num = Math.random(); //Math.random()：得到一个0到1之间的随机数
				    num = Math.ceil(num * arrlength); //num*?的取值范围在0~?
				    if(arr[0] != 0) {
				        var flag = false; // 控制是否存在重复元素
				        // 遍历生产数组中的元素
				        for(var j = 0; j < arr.length; j++) {
				            if(num != arr[j]) {
				                flag = true;
				            } else {
				                flag = false;
				                break;
				            }
				        }
				        if(flag == true) {
				            arr[index++] = num;
				        } else {
				            // 发现有重复元素重新产生新的随机数
				            i--;
				        }
				    } else {
				        arr[index++] = num;
				    }
						
				}
				this.list = arr;
				// console.log(this.list)
			},
			
			
			
			
			
			btn(index){
if(this.ltt==false){
				if(this.bg){
					var t = this.times++
			if(index == t) {
			   this.ab=index
			   if(index==25){
				 clearInterval(this.time)
				
				 if(this.tis > 20){
					 uni.showModal({
					     title: '提示',
					     content: "一共花费：" + this.tis + "秒!你的记忆力相当于一头猪！",
					     success: function (res) {
					         if (res.confirm) {
					             console.log('用户点击确定');
					         } else if (res.cancel) {
					             console.log('用户点击取消');
					         }
					     }
					 });
					 
				 }else if(this.tis > 15 &&this.tis  <= 20){
				   
					 uni.showModal({
					     title: '提示',
					     content: "一共花费：" + this.tis + "秒!你的记忆力相当于一头猪！",
					     success: function (res) {
					         if (res.confirm) {
					             console.log('用户点击确定');
					         } else if (res.cancel) {
					             console.log('用户点击取消');
					         }
					     }
					 });
					  this.tis =0
				 }else if(this.tis > 13 && this.tis  <= 15) {
					 uni.showModal({
					     title: '提示',
					     content: "一共花费：" + this.tis + "秒!你的记忆力处于普通人范围！",
					     success: function (res) {
					         if (res.confirm) {
					             console.log('用户点击确定');
					         } else if (res.cancel) {
					             console.log('用户点击取消');
					         }
					     }
					 });
				    
				 }else if(this.tis > 10 && this.tis  <= 13) {
					 uni.showModal({
					     title: '提示',
					     content: "一共花费：" + this.tis + "秒!很棒，你的记忆力比一般人强！",
					     success: function (res) {
					         if (res.confirm) {
					             console.log('用户点击确定');
					         } else if (res.cancel) {
					             console.log('用户点击取消');
					         }
					     }
					 });
				 
				 }else if(this.tis < 10) {
					 uni.showModal({
					     title: '提示',
					     content: "一共花费：" + this.tis + "秒!卧槽，你还是人么！",
					     success: function (res) {
					         if (res.confirm) {
					             console.log('用户点击确定');
					         } else if (res.cancel) {
					             console.log('用户点击取消');
					         }
					     }
					 });
				    
				 }  
				 
			   }
			}else{
				this.times--
				
			}
				}else{
					uni.showToast({
						title: '请先开始游戏',
						duration: 2000
					});
				}
			
				
				}else{
					if(this.bg){
							var t = this.times++
					if(index == t) {
					   this.ab=index
					   if(index==25){
						 clearInterval(this.time)
						
						 if(this.tis > 20){
							 uni.showModal({
							     title: '提示',
							     content: "一共花费：" + this.tis + "秒!你的记忆力相当于一头猪！",
							     success: function (res) {
							         if (res.confirm) {
							             console.log('用户点击确定');
							         } else if (res.cancel) {
							             console.log('用户点击取消');
							         }
							     }
							 });
							 
						 }else if(this.tis > 15 &&this.tis  <= 20){
						   
							 uni.showModal({
							     title: '提示',
							     content: "一共花费：" + this.tis + "秒!你的记忆力相当于一头猪！",
							     success: function (res) {
							         if (res.confirm) {
							             console.log('用户点击确定');
							         } else if (res.cancel) {
							             console.log('用户点击取消');
							         }
							     }
							 });
							  this.tis =0
						 }else if(this.tis > 13 && this.tis  <= 15) {
							 uni.showModal({
							     title: '提示',
							     content: "一共花费：" + this.tis + "秒!你的记忆力处于普通人范围！",
							     success: function (res) {
							         if (res.confirm) {
							             console.log('用户点击确定');
							         } else if (res.cancel) {
							             console.log('用户点击取消');
							         }
							     }
							 });
						    
						 }else if(this.tis > 10 && this.tis  <= 13) {
							 uni.showModal({
							     title: '提示',
							     content: "一共花费：" + this.tis + "秒!很棒，你的记忆力比一般人强！",
							     success: function (res) {
							         if (res.confirm) {
							             console.log('用户点击确定');
							         } else if (res.cancel) {
							             console.log('用户点击取消');
							         }
							     }
							 });
						 
						 }else if(this.tis < 10) {
							 uni.showModal({
							     title: '提示',
							     content: "一共花费：" + this.tis + "秒!卧槽，你还是人么！",
							     success: function (res) {
							         if (res.confirm) {
							             console.log('用户点击确定');
							         } else if (res.cancel) {
							             console.log('用户点击取消');
							         }
							     }
							 });
						    
						 }  
						 
					   }
					}else{
						// this.times--
						this.times=0
						uni.showToast({
							title: '游戏结束',
							duration: 2000
						});
						clearInterval(this.time)
					}
						}else{
							uni.showToast({
								title: '请先开始游戏',
								duration: 2000
							});
						}
					
					
					
				}
				// console.log(index)
				
			}
			}
		
	}
	
	
</script>

<style>
	li{
		list-style: none;
		width: 20%;
		float: left;
		height: 120rpx;
		text-align: center;
		line-height:120rpx ;
		box-sizing: border-box;
		border: 2rpx #007AFF solid;
	}
	.active {
	 background: red
	}
</style>
